package lysjmaster.base;

import lysjmaster.base.auth.domain.Role;
import lysjmaster.base.auth.repository.RoleRepository;
import lysjmaster.base.common.CommonConstant;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Created by zk on 2019-12-05 5:15
 * @description
 */
@Component
public class InitApplicationRunner implements ApplicationRunner {
    @Resource
    private RoleRepository roleRepository;


    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        //生成管理员
        Role adminRole = roleRepository.findOne(CommonConstant.ADMIN_ID);
        if(adminRole == null){
            Role role = new Role();
            role.setName("管理员");
            role.setId(CommonConstant.ADMIN_ID);
            roleRepository.save(role);
        }



    }
}
